package com.ftg.shopping.carshop.service;

import com.ftg.shopping.carshop.entity.orderdetails;
import com.ftg.shopping.carshop.entity.sp_cartshop;
import com.ftg.shopping.carshop.entity.sp_orderinfo;
import com.ftg.shopping.carshop.mapper.carshopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class carshopService {

    @Autowired
    carshopMapper carshopMapper;

    public List<Map<String,Object>> showcar(String userid){
        return carshopMapper.showcar(userid);
    }

    public int insertcar(sp_cartshop spc){
        return carshopMapper.insertcar(spc);
    }

    public int deletecar(String goodsname,String userid){
        return carshopMapper.deletecar(goodsname,userid);
    }


    @Transactional(rollbackFor = Exception.class)
    public int insertorder(String price,String iphone,String goodsname,String username,String lostmoney){

        int orderld = (int) (Math.random()*10000);
        String[] cla = goodsname.split(" ");
        for (int i = 0;i < cla.length;i++){
            carshopMapper.insertordertetails(orderld,cla[i]);
        }

        carshopMapper.insertorder(orderld,username,lostmoney,price,iphone);
        return 1;
    }




//    public int deletecars(List<Integer> ids){
//        return carshopMapper.deleteBatchIds(ids);
//    }
}
